package patternmining.model.construction;

import java.util.HashSet;
import java.util.Set;

/**Marker Interface with a purely conceptual purpose.
 * The implementing classes provide serviçes used in the analysis of the source file.
 * Its sources are collected in this source file, to group the concaptually related classes 
 * 
 * @version 1.0, 15.07.2008
 * @author Holger Wiehen
 */
interface Analysis {}



class TypePrecedence {
    String getResultType( String type1, String type2 ){
        // Applying the implicit primitiveconversions defined by th Java Language Specification in
        //5.1.2 Widening Primitive Conversion
        //  The following 19 specific conversions on primitive types are called the widening primitive conversions:
        //  * byte to short, int, long, float, or double
        //  * short to int, long, float, or double
        //  * char to int, long, float, or double
        //  * int to long, float, or double
        //  * long to float or double
        //  * float to double 
       
        String dominant = null;
        Set<String> pair = new HashSet<String>();
        pair.add(type1);
        pair.add(type2);        
        
        if( type1.equals( type2) ){
            dominant = type1;
        }
        else{
            Set<String> primitiveTypes = new HashSet<String>();
            primitiveTypes.add("java.lang.Double");
            primitiveTypes.add("java.lang.Float");
            primitiveTypes.add("java.lang.Long");
            primitiveTypes.add("java.lang.Integer");
            primitiveTypes.add("java.lang.Short");
            primitiveTypes.add("java.lang.Byte");
            primitiveTypes.add("java.lang.Character");
            if( primitiveTypes.contains(type1) && primitiveTypes.contains(type2) ){
                if( pair.contains("java.lang.Double") ){
                    dominant = "java.lang.Double";
                }
                else if( pair.contains("java.lang.Float") ){
                    dominant = "java.lang.Float";
                }
                else if( pair.contains("java.lang.Long") ){
                    dominant = "java.lang.Long";
                }
                else if( pair.contains("java.lang.Integer") ){
                    dominant = "java.lang.Integer";
                }
                else if( pair.contains("java.lang.Short") ){
                    dominant = "java.lang.Short";
                }
                else{
                    dominant = "null";
                }
            }
        } 
        return dominant;
    }
}
